<template>
  <div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="areaName" label="楼栋名称" width="180"></el-table-column>
      <el-table-column prop="terminalsCount" label="楼栋表数量" width="180"></el-table-column>
      <el-table-column prop="metersCount" label="户表数量"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleViewTerminals(scope.row)"
            v-hasPermi="['region:zone:edit']"
          >楼栋表明细
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleViewMeters(scope.row)"
            v-hasPermi="['region:zone:edit']"
          >户表明细
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="楼栋表明细" :visible.sync="open1" width="1000px"
               :close-on-click-modal="false" :show-close="false" append-to-body>
      <TerminalHooking ref="refDmaBuildingTerminalHooking"/>

      <div slot="footer" class="dialog-footer">
        <el-button type="danger" @click="handleHookingClose('1')">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog title="楼栋表明细" :visible.sync="open2" width="1000px"
               :close-on-click-modal="false" :show-close="false" append-to-body>
      <MeterHooking ref="refDmaBuildingMeterHooking"/>

      <div slot="footer" class="dialog-footer">
        <el-button type="danger" @click="handleHookingClose('2')">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getBuildingTerminalsAndMeters} from '@/api/leakage/zone'
import TerminalHooking from "./TerminalHooking";
import MeterHooking from "./MeterHooking";

export default {
  name: "BuildingTerminalsAndMeters",
  components: {
    TerminalHooking,
    MeterHooking
  },
  data() {
    return {
      editingZoneObj: undefined,
      tableData: [],
      open1: false,
      open2: false,
    }
  },
  methods: {
    updateEditingZone(zone) {
      this.editingZoneObj = zone
      this.loadBuildingTerminalsAndMeters()
    },
    loadBuildingTerminalsAndMeters() {
      getBuildingTerminalsAndMeters({areaId: this.editingZoneObj.areaId}).then(res => {
        this.tableData = res.data
      })
    },
    handleViewTerminals(building) {
      this.open1 = true
      this.$nextTick(() => {
        this.$refs.refDmaBuildingTerminalHooking.updateEditingZone(building)
      })
    },
    handleViewMeters(building) {
      this.open2 = true
      this.$nextTick(() => {
        this.$refs.refDmaBuildingMeterHooking.updateEditingZone(building)
      })
    },
    handleHookingClose(t) {
      if (t === '1') {
        this.open1 = false
      } else {
        this.open2 = false
      }
      this.loadBuildingTerminalsAndMeters()
    }
  }
}
</script>

<style scoped>

</style>
